import { getTradeInfo,getUserAddress } from "../../api/api";
export default{
    state:{
        tradeInfo:{},
        usersAddress:[]
    },
    mutations:{
        getTradeInfo(state,trade){
            state.tradeInfo=trade
        },
        getUserAddress(state,usersAddress){
            state.usersAddress=usersAddress
        },
    },
    actions:{
        async getTradeInfo(store){
            try{
                const {code:tradeCode,data:trade}=await getTradeInfo();
                const {code:addressCode,data:usersAddress}=await getUserAddress();
                // console.log(data,message);
                if(tradeCode===200&&addressCode===200){
                    store.commit('getTradeInfo',trade)
                    store.commit('getUserAddress',usersAddress)
                }
            }catch(e){
                return Promise.reject(e)
            }
        }
    },
    getters:{
        selectedUsers(state){
            return state.usersAddress.findIndex(item=>item.isDefault==='1')
        }
    }
}